import matplotlib.pyplot as plt
import pandas as pd
import math
import numpy as np

class Q:
 
    def __init__(self):
        self.A = 4.0817
        self.B = 4.0817
        self.phi = 0.125
        self.alpha = 0.43
        self.beta = 0.78
        self.theta = 0.576
        
        # self.h = 1
        # self.phi1 = 1
        # self.phi2 = 1
        self.gamma = 0.65
        self.rou  = 0.65
        
        # self.Ltop = 1 
        # self.Lbottom = 1 
        # self.R = 1
        # self.Rindex = 1

    def change_beta(self,_beta):
        self.beta = _beta
    
    def change_gamma(self,_gamma):
        self.gamma = _gamma
    
    def change_theta(self,_theta):
        self.theta = _theta
    
    def C25(self,_nt):
        
        # self.rou  = _ROU
        self.nt  = _nt
        # GT = self.A * self.phi * self.rou
        # GT = GT * self.beta * (1 - self.alpha)
        
        GT = self.A * self.beta * self.rou
        GT = GT * (1 - self.alpha)
        GT = GT * (1 - self.phi * self.nt)

        GB = self.rou * self.beta + self.gamma + 1
        GB = GB * self.nt


        self.phi1 = GT / GB
        
        
        KT = pow(self.A,self.theta)
        KT = KT * self.B
        KT = KT * pow(self.gamma,self.theta)
        KT = KT * pow(self.theta,self.theta)
        KT = KT * pow((1 - self.alpha),self.theta)
        KT = KT * pow((1 - self.phi * self.nt),self.theta)
        
        # KB = 1 - self.theta
        KB = pow(self.nt,self.theta)
        KB = KB * pow(1 + self.rou * self.beta + self.gamma,self.theta)
        
        self.phi2 = KT / KB
        
        _L = pow(self.phi1 ,self.alpha * self.theta)
        _L = _L * pow(self.phi2,(1-self.alpha))
        
        _index = 1 - self.alpha * (1-self.theta)
        _index = 1 / _index  
        _R25 =  pow( _L ,_index )
        return _R25
        
        
    # def C29(self):
        
    #     self.Ltop = pow(self.A,2)*self.phi
    #     self.Ltop = self.Ltop * self.beta * self.theta
    #     self.Ltop = self.Ltop * pow((1-self.alpha),2)
    #     self.Ltop = self.Ltop * self.h
        
    #     self.Lbottom = self.gamma * pow((1-self.theta),2)
    #     self.Lbottom = self.gamma * (1-self.alpha*(1-self.theta))
        
    #     self.Rindex = self.alpha * (2-self.theta) - 1
    #     self.Rindex = self.Rindex/(1-self.alpha*(1-self.theta))
        
    #     self.R = self.phi1/self.phi2
    #     self.R = pow(self.R,self.Rindex)
        
        
        
    #     _R29 = self.Ltop / self.Lbottom * self.R 
    #     return _R29
    
    # def C11(self,_ROU):
        
    #     self._ROU = _ROU
    #     _NT = (1 - self.alpha) * self.gamma
    #     _NB = 1 + self._ROU * self.beta + self.gamma
    #     _NB = _NB * self.phi
        
    #     _R11 = _NT / _NB
    #     return _R11
        

_d = Q()

print(_d.C25(0.1))

X_n = np.linspace(0.6,3,100)

# X_ROU = np.linspace(0,1,100)

Y_I = np.empty(100, dtype = float)
# Y_n = np.empty(100, dtype = float)

for i in range(0,100):
    _d = Q()
    Y_I[i]=_d.C25(X_n[i])
    # Y_n[i]=_d.C11(X_ROU[i])
    # print(Y[i])

plt.figure(figsize=(12,6))
# plt.subplot(1,2,1)
# plt.title("func 27")
# plt.xlabel("ρ")
# plt.ylabel("I")
# plt.plot(X_ROU,Y_I)

# plt.subplot(1,2,2)
plt.title("2-1")
plt.xlabel("n")
plt.ylabel("I")
plt.plot(X_n,Y_I)

plt.figure(figsize=(27,9))

plt.subplot(1,3,1)
plt.title("3-3-1 beta")

beta_list = [0.9,0.7,0.5,0.3,0.1]
for _T in beta_list:
  for i in range(0,100):
      _d = Q()
      _d.change_beta(_T)
      Y_I[i]=_d.C25(X_n[i])
  plt.xlabel("n")
  plt.ylabel("I")

  plt.plot(X_n,Y_I)

plt.legend(labels=beta_list)

# plt.figure(figsize=(12,6))
plt.subplot(1,3,2)
plt.title("3-3-2 gamma")

gamma_list = [0.3,0.5,0.7,0.9,1]
for _T in gamma_list:
  for i in range(0,100):
      _d = Q()
      _d.change_gamma(_T)
      Y_I[i]=_d.C25(X_n[i])
  plt.xlabel("n")
  plt.ylabel("I")
  plt.plot(X_n,Y_I)

plt.legend(labels=gamma_list)


# plt.figure(figsize=(12,6))
plt.subplot(1,3,3)
plt.title("3-3-3 theta")

theta_list = [0.5,0.55,0.60,0.65,0.7]
for _t in theta_list:
  for i in range(0,100):
      _d = Q()
      _d.change_theta(_t)
      Y_I[i]=_d.C25(X_n[i])
  plt.xlabel("n")
  plt.ylabel("I")
  plt.plot(X_n,Y_I)

plt.legend(labels=theta_list)
plt.show()
    